/**
 * 
 */
package utils;

import junit.framework.TestCase;

/**
 * @author CC
 *
 */
public class BinStuffsTest extends TestCase 
{

    public void test_toHexString()
    {
        byte[] bytes = { (byte)0xF1, (byte)0xAB, 0x23, 0x59 };
        
        test_toHexString(bytes);
    }

    public void test_toHexString(final byte[] bytes)
    {
        String hexa = BinStuffs.toHexString(bytes);
        byte[] nVal = BinStuffs.hexStringToByteArray( hexa );
        
        assertEquals( "byte[] not same length", bytes.length, nVal.length );
        
        for( int i = 0; i<bytes.length; i++ ) {
            assertEquals( "byte["+i+"] not same value", bytes[i], nVal[i] );
        }
    }
    
    public void test_hexStringToByteArray()
    {
        String hexa = "ABCDEF12";
        
        test_hexStringToByteArray( hexa );
    }

    public void test_hexStringToByteArray(String hexa)
    {
        byte[] nVal = BinStuffs.hexStringToByteArray( hexa );
        String nHex = BinStuffs.toHexString(nVal);
        
        assertEquals( "String not same length", hexa.length(), nHex.length() );
        assertEquals( "String not same value", hexa, nHex );
    }
    
    public void test_intToByteArray()
    {
        int          aInt  = 0xF1F2F3F4;
        final byte[] bytes = BinStuffs.intToByteArray(aInt);
        
        assertEquals( "bad length",4, bytes.length);
        assertEquals( "bad value byte[0]",(byte)0xF1, bytes[0]);
        assertEquals( "bad value byte[1]",(byte)0xF2, bytes[1]);
        assertEquals( "bad value byte[2]",(byte)0xF3, bytes[2]);
        assertEquals( "bad value byte[3]",(byte)0xF4, bytes[3]);
    }
}
